package YAPclient;

import YAPclient.sound.ISound;
import YAPclient.sound.MusicClip;
import YAPclient.sound.Sound;
import YAPclient.sound.SoundList;
import YAPclient.sound.SoundList.SoundName;
import YAPenvironment.YAPconstant;

/**
 * This class creates the actual client. It contains some basic information like 
 * the client's name as well as the IP address and port being used.
 */

public class Client implements IClient{
	String m_Name;
	String m_IP;
	int m_Port;
	int m_udpPort;
	boolean sound = true;
	
	/**
	 * Creates a new client
	 */
	public Client(){
		new SoundList();
		setUpSounds();
	}
	
	public String getName(){
		return m_Name;
	}
	
	public void setName(String name){
		m_Name = name;
	}
	public String getIP(){
		return m_IP;
	}
	public void setIP(String ip){
		m_IP = ip;
	}
	
	public int getPort(){
		return m_Port;
	}
	
	public void setPort(int port){
		m_Port = port;
	}
	
	public void setUdpPort(int port){
		m_udpPort=port;
	}
	
	public int getUdpPort(){
		return m_udpPort;
	}
	
	public boolean getSound(){
		return sound;
	}
	public void setSound(boolean toBe){
		sound=toBe;
	}

	@Override
	public void playSound(SoundName sound) {
		sound.play();
	}

	@Override
	public void pauseSounds() {
		for(SoundName sound: SoundName.values()){
			sound.pause();
		}
	}

	@Override
	public void clearSounds() {
		for(SoundName sound: SoundName.values()){
			sound.clear();
		}
	}
	
	@Override
	public void setUpSounds(){
		//creates the sounds list with the same length as the enum sound names
		SoundList.sounds = new ISound[SoundName.values().length];
//		Tne bounce sounds are (modified) from freesound:
//		jaw_harp9.mp3 by 3bagbrew ( http://freesound.org/people/3bagbrew/ )	
		SoundList.sounds[SoundName.bounce.ordinal()] = new Sound(YAPconstant.class.getResource( "sounds/boing_normal.wav"), 4);
		SoundList.sounds[SoundName.bounceBig.ordinal()] = new Sound(YAPconstant.class.getResource( "sounds/boing_big.wav"), 4);
		SoundList.sounds[SoundName.bounceSmall.ordinal()] = new Sound(YAPconstant.class.getResource( "sounds/boing_small.wav"), 4);
		SoundList.sounds[SoundName.playerLostLife.ordinal()] = new Sound(YAPconstant.class.getResource( "sounds/beep-04.wav"), 4);
		SoundList.sounds[SoundName.startGame.ordinal()] = new Sound(YAPconstant.class.getResource( "sounds/beep-06.wav" ), 4);
		SoundList.sounds[SoundName.rotate.ordinal()] = new MusicClip(YAPconstant.class.getResource( "sounds/korobeiniki.wav" ));
		
		SoundList.SoundName.setSounds();
	}

	@Override
	public void resumeSounds() {
		for(SoundName sound: SoundName.values()){
			sound.resume();
		}
	}
	
}
